﻿using UnityEngine;
namespace Lv1
{
    /// <summary>
    /// 全局GameObject单例抽象基类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class DDOLSingleton<T> : MonoBehaviour where T : DDOLSingleton<T> {
        protected static T _Instance = null;

        public static T Instance
        {
            get
            {
                if (null==_Instance)
                {
                    GameObject go = GameObject.Find(typeof(T).ToString());
                    if (null==go)
                    {
                        go = new GameObject(typeof(T).ToString());
                        DontDestroyOnLoad(go);
                    }
                    _Instance = go.GetOrAddComponent<T>();
                }
                return _Instance;
            }
        }

        private void OnApplicationQuit()
        {
            _Instance = null;
        }

    }
}